#!/bin/bash
#
# Copyright 2015-2017 Adrian DC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# === Git Projects Statistics ===
function gitstat()
{
  # Usage
  if [ -z "${2}" ]; then
    echo '';
    echo ' Usage: gitstat <remote> <branch> [stats_only] (Git history with remote comparator)';
    echo '';
    return;
  fi;

  # Informations
  echo "git fetch ${1} ${2}; git rev-list --left-right --count HEAD...FETCH_HEAD;";

  # Request
  git fetch "${1}" "${2}";
  if [ ! -z "${3}" ]; then
    git --no-pager diff --stat HEAD FETCH_HEAD;
  else
    git --no-pager diff HEAD...FETCH_HEAD;
  fi;

  # Comparison
  echo '';
  echo -n ' New changes - missing : ';
  git rev-list --left-right --count HEAD...FETCH_HEAD;
}

# === Git Projects Statistics (shortcuts) ===
alias gitst='gitremoteverify origin gitrao && gitstat origin lineage-15.0';
alias gitsto='gitremoteverify origin gitrao && gitstat origin $(git rev-parse --abbrev-ref HEAD)';
alias gitstom='gitremoteverify origin gitrao && gitstat origin master';
alias gitsta='gitremoteverify $(githubusername) gitraa && gitstat $(githubusername) lineage-15.0';
alias gitstam='gitremoteverify $(githubusername) gitraa && gitstat $(githubusername) master';
alias gitstg='gitremoteverify github false && gitstat github';
alias gitstaosp='gitremoteverify aosp false && gitstat aosp master';
alias gitstsony='gitremoteverify origin gitraos && gitstat origin aosp/LA.UM.5.5.r1';
alias gitstfa='gitrao; gitremoteverify $(githubusername) gitraa && gitstat $(githubusername) lineage-15.0 true';
